#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2022/4/11 3:27 下午
# @Author : wang
# @Email : 136697880@qq.com
# @File : SendSms.py
# @Project : bugmgr

import requests
import hashlib
import datetime
from django.conf import settings


def SendSms(mb, ms):
    url = settings.URL
    uid = settings.UID
    pw = settings.PASSWORD
    tm = datetime.datetime.now().strftime('%Y%m%d%H%M%S')

    # 创建md5对象
    h = hashlib.md5()
    h.update(bytes(pw + tm, encoding='utf-8'))
    md5_pw = h.hexdigest()

    data = {'uid': uid, 'pw': md5_pw, 'mb': mb, "ms": ms.encode('utf-8'), 'tm': tm}

    dataStr = ''
    for key in data:
        dataStr += "{}={}&".format(key, data[key])
    res = requests.post(url, data)
    print(res.text)
    return res.text

